//
//  SwizzingTestViewController.m
//  TestDemo
//
//  Created by fengxijun on 3/3/16.
//  Copyright © 2016 goappbox. All rights reserved.
//

#import "SwizzingTestViewController.h"
#import "UIExtesionButton.h"

@implementation SwizzingTestViewController

-(void)viewDidLoad
{
    NSLog(@"%s",__PRETTY_FUNCTION__);
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    UIExtesionButton *button = [UIExtesionButton buttonWithType:UIButtonTypeCustom];
    [button setLongPressButtonHandle:^(UIExtesionButton *button) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"长按" message:@"" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles: nil];
        [alert show];
    }];
    
    NSAssert(button != nil, @"button is Null");
    
    [button setTapButtonHandle:^(UIExtesionButton *button) {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"点击" message:@"" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles: nil];
        [alert show];
    }];
    [button setFrame:CGRectMake(100.f, 80.f, 100.f, 40.f)];
    button.layer.borderWidth = 1.f;
    button.layer.borderColor = [UIColor grayColor].CGColor;
    [button setTitle:@"测试点击" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
    [button setBackgroundImage:[self imageWithColor:[UIColor orangeColor]] forState:UIControlStateNormal];
    [button setBackgroundImage:[self imageWithColor:[UIColor yellowColor]] forState:UIControlStateHighlighted];
//    [button setTitleColor:[UIColor yellowColor] forState:UIControlStateHighlighted];
//    [button setTitleColor:[UIColor orangeColor] forState:UIControlStateSelected];
    [self.view addSubview:button];
}

- (UIImage *)imageWithColor:(UIColor *)color
{
    CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetFillColorWithColor(context, [color CGColor]);
    CGContextFillRect(context, rect);
    
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    
    return image;
}

@end
